<?php
namespace app\common;

class Net
{    
    public static function http($url, $postfields='', $method='GET', $headers=array())
    {
        if(strpos($url,'http') === false)
        {
           return;
        }

        $ci=curl_init();
        curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($ci, CURLOPT_TIMEOUT, 30);
        curl_setopt ($ci, CURLOPT_HTTPHEADER, $headers);
        if($method=='POST')
        {
            curl_setopt($ci, CURLOPT_POST, 1);
            if($postfields!='')
            {
                if(is_array($postfields)){
                    $postfields = http_build_query($postfields,null,'&');
                }
                
                curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
            }
        }

        curl_setopt($ci, CURLOPT_URL, $url);
        $response=curl_exec($ci);
        curl_close($ci);
        return $response;
    }    
}